<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
 <head>
  <title>inputEx - MultiAutoComplete Usage</title>

<!-- YUI CSS -->
<link rel="stylesheet" type="text/css" href="../lib/yui/reset/reset-min.css">
<link rel="stylesheet" type="text/css" href="../lib/yui/fonts/fonts-min.css">
<link rel="stylesheet" type="text/css" href="../lib/yui/container/assets/container.css"> 
<link rel="stylesheet" type="text/css" href="../lib/yui/assets/skins/sam/skin.css">

<!-- InputEx CSS -->
<link type='text/css' rel='stylesheet' href='../css/inputEx.css' />

<!-- Demo CSS -->
<link rel="stylesheet" type="text/css" href="css/demo.css"/>
<link rel="stylesheet" type="text/css" href="css/dpSyntaxHighlighter.css">

 </head>

 <body class="yui-skin-sam">

<p class='demoTitle'>inputEx - MultiAutoComplete Usage</p>


<!-- Example 1 -->
<div class='exampleDiv'>

	<p class="title">Basic MultiAutoComplete creation</p>
	
	<p>Use the following code to create a basic inputEx MultiAutoComplete.</p>

	<div class='demoContainer' id='container1'></div>

	<div class='codeContainer'>
				<textarea name="code" class="JScript">
			YAHOO.util.Event.addListener(window, 'load', function() {

				// Example 1	
				var el = YAHOO.util.Dom.get('container1');

				var field = new YAHOO.inputEx.MultiAutoComplete({
					parentEl: el, 
					label: 'Search US state',

					// see http://developer.yahoo.com/yui/examples/autocomplete/assets/js/states_jsfunction.js for getState function
					datasource: new YAHOO.widget.DS_JSFunction( getStates),

					// Format the hidden value (value returned by the form)
					returnValue: function(oResultItem) {
						return oResultItem[1];
					},

					// autocompleter options
					autoComp: {
						forceSelection: true,
						minQueryLength: 2,
						maxResultsDisplayed: 50,
						formatResult: function(oResultItem, sQuery) {
			       	   var sMarkup = oResultItem[0] + " (" + oResultItem[1] + ")";
			       	   return sMarkup;
			    	   }
					}
				});

				var logDiv = YAHOO.inputEx.cn('div', null, null, "<br />");
				el.appendChild(logDiv);

				field.updatedEvt.subscribe(function(e,params) {
					var value = YAHOO.lang.JSON.stringify(params[0]);
					logDiv.appendChild( YAHOO.inputEx.cn('div',null,null,"Updated at "+(new Date())+" "+value+"<br />") );
				});

			});
		</textarea>
			</div>

</div>


<!-- YUI Library -->
<script type="text/javascript" src="../lib/yui/yahoo/yahoo-min.js"></script> 
<script type="text/javascript" src="../lib/yui/dom/dom-min.js"></script> 
<script type="text/javascript" src="../lib/yui/event/event-min.js"></script>
<script type="text/javascript" src="../lib/yui/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="../lib/yui/datasource/datasource-min.js"></script>
<script type="text/javascript" src="../lib/yui/autocomplete/autocomplete-min.js"></script>

<!-- For the state autocompleter -->
<script src="http://developer.yahoo.com/yui/examples/autocomplete/assets/js/states_jsfunction.js" type='text/javascript'></script>

<!-- Just for the example (not required by MultiAutoComplete)-->
<script type="text/javascript" src="../lib/yui/json/json-min.js"></script>

<!-- InputEx -->
<script src="../js/inputex.js"  type='text/javascript'></script>
<script src="../js/Visus.js"  type='text/javascript'></script>
<script src="../js/Field.js"  type='text/javascript'></script>
<script src="../js/fields/StringField.js"  type='text/javascript'></script>
<script src="../js/fields/AutoComplete.js"  type='text/javascript'></script>
<script src="../js/widgets/ddlist.js"  type='text/javascript'></script>
<script src="../js/fields/MultiAutoComplete.js"  type='text/javascript'></script>

<script>

YAHOO.util.Event.addListener(window, 'load', function() {

	// Example 1	
	var el = YAHOO.util.Dom.get('container1');
	
	var field = new YAHOO.inputEx.MultiAutoComplete({
		parentEl: el, 
		label: 'Search US state',
		
		// see http://developer.yahoo.com/yui/examples/autocomplete/assets/js/states_jsfunction.js for getState function
		datasource: new YAHOO.widget.DS_JSFunction( getStates),
		
		// Format the hidden value (value returned by the form)
		returnValue: function(oResultItem) {
			return oResultItem[1];
		},
		
		// autocompleter options
		autoComp: {
			forceSelection: true,
			minQueryLength: 2,
			maxResultsDisplayed: 50,
			formatResult: function(oResultItem, sQuery) {
       	   var sMarkup = oResultItem[0] + " (" + oResultItem[1] + ")";
       	   return sMarkup;
    	   }
		}
	});
	
	var logDiv = YAHOO.inputEx.cn('div', null, null, "<br />");
	el.appendChild(logDiv);
	
	field.updatedEvt.subscribe(function(e,params) {
		var value = YAHOO.lang.JSON.stringify(params[0]);
		logDiv.appendChild( YAHOO.inputEx.cn('div',null,null,"Updated at "+(new Date())+" "+value+"<br />") );
	});
		
});

</script>

<script src="js/dpSyntaxHighlighter.js"></script>
<script language="javascript"> 
dp.SyntaxHighlighter.HighlightAll('code');
</script>

 </body>
</html>